package org.example.game.history;

import java.util.HashMap;

/**
 * @Description: TODO
 * @Author wyatt
 * @Data 2024/05/05 10:54
 */
public class Solution100275 {

    public static void main(String[] args) {
        System.out.println(new Solution100275().minimumOperationsToMakeKPeriodic("leetcoleet", 2));
    }

    public int minimumOperationsToMakeKPeriodic(String word, int k) {
        int size = word.length() / k;
        String maxMatchWord = "";
        int maxMatch = 0;
        HashMap<String, Integer> matchMap = new HashMap<>();
        for(int i=0;i<size;i++){
            String subWord = word.substring(i*k,i*k+k);
            if(!matchMap.containsKey(subWord)){
                matchMap.put(subWord, 0);
            }

            matchMap.put(subWord, matchMap.get(subWord) + 1);

            if(matchMap.get(subWord) > maxMatch){
                maxMatch = matchMap.get(subWord);
                maxMatchWord = subWord;
            }
        }

        return size - matchMap.get(maxMatchWord);
    }

}
